package com.travel.server.manager.impl.command.message;

import com.travel.server.manager.dto.request.message.QueryMessageMailDetailRequest;
import com.travel.server.manager.dto.response.message.QueryMessageMailDetailResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.MessageDal;
import com.travel.server.manager.model.MessageTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018\11\17 0017 16:26
 * @Desc:
 */
@Component
public class QueryMessageMailDetailCommand extends AbstractCommand<QueryMessageMailDetailRequest, QueryMessageMailDetailResponse> {

    @Autowired
    private MessageDal messageDal;

    @Override
    protected void checkInput(QueryMessageMailDetailRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryMessageMailDetailResponse handle(QueryMessageMailDetailRequest request) {
        checkInput(request);
        MessageTemplate messageTemplate = messageDal.selectById(request.getId());
        QueryMessageMailDetailResponse response = new QueryMessageMailDetailResponse();
        response.setContent(messageTemplate.getMessageContent());
        response.setRemark(messageTemplate.getMailRemark());
        response.setSender(messageTemplate.getMailSender());
        response.setTheme(messageTemplate.getMailTheme());
        response.setName(messageTemplate.getMessageTitle());
        return response;
    }
}
